package work.fram;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//对文件进行分组处理
public abstract class FileGroup {

    private GroupsWrapper groupsWrapper;

    public GroupsWrapper getGroupsWrapper() {
        return groupsWrapper;
    }

    public void setGroupsWrapper(GroupsWrapper groupsWrapper) {
        this.groupsWrapper = groupsWrapper;
    }

    protected Map<String, String> mapping = new HashMap<>();

    //进行映射
    protected void map(String k, String v) {
        mapping.put(k, v);
    }

    public abstract String[] names();

    public void handle(Map<String, String> map, String name, String idcard, File file) {

        Map<String, String> am = new HashMap<>();

        for (String key : mapping.keySet()) {
            String ak = mapping.get(key);
            String r = map.get(key);
            if (r != null) {
                am.put(ak, r.replace("\n", "").replace("\"", "\\\"").replace("'", "\\'"));
            }
        }

        afterMapping(am, name, idcard, file);

    }

    public abstract void afterMapping(Map<String, String> map, String name, String idcard, File file);
}
